package main

import (
	"encoding/hex"
	"encoding/json"
	"fmt"
	"unicode/utf8"
)

func hexcustom() {
	var data = "Hello World! kso 孔宥芯"
	//编码
	encodeToString := hex.EncodeToString([]byte(data))
	fmt.Println("encodeToString", encodeToString)
	//解码
	decodeString, err := hex.DecodeString(data)
	fmt.Println("HEX DECODED : ", decodeString, err)
}
func unicodingtest() {
	type rune = int32
	str := "GO爱好者"
	fmt.Printf("%q", []int32(str))
	fmt.Printf("%x", []rune(str))
	fmt.Printf("%x \n", []byte(str))

	var bs = []byte(str)
	fmt.Printf("%x", bs)
	decodeRune, size := utf8.DecodeRune(bs)
	fmt.Printf("decodeRune: %d, size=%d \n", decodeRune, size)
}

type Person struct {
	Name  string
	Age   int
	Email string
}

func test_12() {
	//str := "爱好者"
	p := make([]byte, 3)
	fmt.Println(p)
	n := utf8.EncodeRune(p, '爱')
	fmt.Printf("test_12：[% x],EncodeRune： %d \n", p, n)

	b := []byte(`{"Name":"tom","Age":20,"Email":"tom@gmail.com","Parents":["big tom","kite","kite2","kite3","kite4"],"jsonStutrs":{"age":1233,"age2":1233}}`)
	var f interface{}
	json.Unmarshal(b, &f)
	fmt.Printf("f: %v\n", f)
	if m, ok := f.(map[string]interface{}); ok {
		if par, ok := m["Parents"].([]interface{}); ok {
			for _, v := range par {
				if par, ok := v.([]interface{}); ok {
					fmt.Println(par)
				}
				fmt.Println(v)
			}
		}
	}
	if m, ok := f.(map[string]interface{}); ok {
		if par, ok := m["jsonStutrs"].(map[string]interface{}); ok {
			fmt.Println(par["age"])
		}
	}
}
